/**
 * @version $Id: update.js 23 2011-11-22 08:04:09Z nhnoah $
 */
var selected_item_type;
var selected_item_id;
var mouse_x;
var mouse_y;

var ms_ie = document.all?true:false;
if (!ms_ie) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = update_mouse_xy;

function update_mouse_xy(e)
{
	if(ms_ie)
	{
		mouse_x = event.clientX + document.body.scrollLeft;
		mouse_y = event.clientY + document.body.scrollTop;
	}
	else
	{
		mouse_x = e.pageX;
		mouse_y = e.pageY;
	}
	
	return true
}

function show_div(item_type, item_id)
{
	selected_item_type = item_type;
	selected_item_id = item_id;
	
	x = mouse_x;
	y = mouse_y;
	
	//some browsers may return negative values
	if(x < 0) x = 0;
	if(y < 0) y = 0;
	
	document.getElementById('file_edit_box').style.display = 'block';
	document.getElementById('file_edit_box').style.left = x-8+'px';
	document.getElementById('file_edit_box').style.top = y-8+'px';
}

function mouse_out_handler(event)
{
	var toElement = null;
	
	if(event.relatedTarget)
		toElement = event.relatedTarget;
	else if(event.toElement)
		toElement = event.toElement;
	
	while (toElement && toElement.tagName != "DIV")
		toElement = toElement.parentNode;
	
	if(!toElement)
		document.getElementById('file_edit_box').style.display = 'none';
}

function check_for_update() 
{
	var xhr;
	try	{ xhr = new XMLHttpRequest();}
	catch(e)
	{
		try
		{
			xhr = new ActiveXObject("Msxml12.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				return false;
			}
		}
	}
	xhr.onreadystatechange = function()
	{
		document.getElementById('checking_gif').style.display = 'block';
		document.getElementById('update_link_container').innerHTML = '';
		if(xhr.readyState == 4)
		{
			document.getElementById('checking_gif').style.display = 'none';
			if(xhr.responseText == 1)
			{
				document.getElementById('update_link_container').innerHTML = '<a href="http://dir-list.sourceforge.net/process/redir_to_update.php" target="_blank">'+ msys.lang.update_available +'!</a>';
			}
			else
			{
				document.getElementById('update_link_container').innerHTML = msys.lang.noupdate_available;
			}
		}
	}
	xhr.open("GET", msys.base + "version_check.php?version=0.3.0", true);
	xhr.send(null);
}